//
//  LoginAlertView.swift
//  XGamesLive
//
//  Created by ios on 2024/5/14.
//

import UIKit
import MXCommonModule

class LoginAlertView: UIView {

    typealias SureHnadler = ()->Void
    
    private var block: SureHnadler?
    
    override init(frame: CGRect) {
        super.init(frame: frame)
    }
    
    required init?(coder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

}

extension LoginAlertView{
    func dismiss(){
        self.removeFromSuperview()
    }
}

extension LoginAlertView{
    @objc private func dismissAction(){
        self.dismiss()
    }
    
    @objc private func sureAction(){
        self.dismiss()
        if let action = self.block {
            action()
        }
    }
}

extension LoginAlertView{
    func showAlertView(_ sureBlock: SureHnadler?){
        self.block = sureBlock
        let contentView = UIView().then { make in
            make.backgroundColor = UIColor.hexColor("#191A1D")
            make.layerCornerRadius = 12.0
        }
        let titleText = UILabel().then { make in
            make.text = "Eula"
            make.font = UIFont.pingfangSC_Regular(fontSize: 18.0)
            make.textColor = .white
        }
        let closeButton = UIButton().then { make in
            make.setImage(imageWithName("icon_xgl_close_gray"), for: .normal)
            make.addTarget(self, action: #selector(self.dismissAction), for: .touchUpInside)
        }
        let textView = UITextView().then { make in
            make.text = "This End User License Agreement ('Agreement') is a legal agreement between you ('User' or 'you') and XGames Live ('we,' 'us,' or 'our') regarding your use of our mobile application ('App'). By downloading, installing, or using the App, you agree to be bound by the terms of this Agreement. If you do not agree to these terms, do not download, install, or use the App.\n1. License Grant\n\nThis EULA governs your access and use of the Product Software. This EULA gives you specific legal rights, and you may also have other legal rights in addition, which vary from jurisdiction to jurisdiction. The disclaimers, exclusions, and limitations of liability under this EULA will not apply to the extent prohibited by applicable law. Some jurisdictions do not allow the exclusion of implied warranties or the exclusion or limitation of incidental or consequential damages or other rights, so those provisions of this EULA may not apply to you.\n\nTHIS IS A LEGAL AGREEMENT. BY ACCESSING AND USING THE PRODUCT SOFTWARE, YOU ARE ACCEPTING AND AGREEING TO THIS EULA ON BEHALF OF YOURSELF OR THE ENTITY YOU REPRESENT IN CONNECTION WITH THE ACCESS. YOU REPRESENT AND WARRANT THAT YOU HAVE THE RIGHT, AUTHORITY, AND CAPACITY TO ACCEPT AND AGREE TO THIS EULA ON BEHALF OF YOURSELF OR THE ENTITY YOU REPRESENT. YOU REPRESENT THAT YOU ARE OF SUFFICIENT LEGAL AGE IN YOUR JURISDICTION OR RESIDENCE TO USE OR ACCESS THE PRODUCT SOFTWARE AND TO ENTER INTO THIS EULA. IF YOU DO NOT AGREE WITH ANY OF THE PROVISIONS OF THESE TERMS, YOU SHOULD CEASE ACCESSING OR USING THE PRODUCT SOFTWARE.\n\nAS DESCRIBED BELOW, YOU ARE CONSENTING TO AUTOMATIC SOFTWARE UPDATE OF THE PRODUCT SOFTWARE. IF YOU DO NOT AGREE, YOU SHOULD NOT USE THE PRODUCT SOFTWARE.\n\nAS DESCRIBED BELOW, SECTION 9 DESCRIBES IMPORTANT LIMITATIONS OF THE PRODUCT SOFTWARE AND RELATED SERVICES, ESPECIALLY IN CONNECTION WITH LIFE SAFETY AND CRITICAL USES. PLEASE READ THESE DISCLOSURES CAREFULLY, AS YOU ARE ACKNOWLEDGING THEM AND ACCEPTING THEM.\n\n1. User Generated Content\n- You understand and agree that our Services may review and delete any content, message, photo, profile, video, sound (collectively, 'Content') that is in the sole judgment of us.\n- You are solely responsible for the Content that you publish or display (hereinafter, 'post') on the Service or any material or information that you transmit to other Members.\n- By posting any Content to the public areas of the mobile application and website, you hereby grant us the non-exclusive, fully paid, worldwide license to use, reproduce, publicly perform and display such Content on the mobile application and website, including without limitation distributing part or all of the mobile application and website in any media formats and through any media channels. You represent and warrant that: (i) you own the Content posted by you on the mobile application and website or otherwise have the right to grant the license set forth in this section, and (ii) your Content does not violate the privacy rights, publicity rights, copyright rights, or other intellectual property rights of any person. You agree to pay all royalties and fees owing to any person by reason of any Content you post on the mobile application and website.\n- The following is a partial list of the kind of Content that is illegal or prohibited on the mobile application and website. We reserve the right to investigate and take appropriate legal action in its sole discretion against anyone who violates this provision, including without limitation, removing the offending communication from the Service and terminating the membership of such violators.\nProhibited Content includes Content that:\n- is patently offensive and promotes racism, sexism, bigotry, hatred or physical harm of any kind against any group or individual, any content that is obscene, pornographic or otherwise may offend human dignity.\n- Harasses or advocates harassment of another person or contains language which could be deemed offensive or is likely to harass, upset, embarrass, alarm or annoy any other person;\n- involves the transmission of 'junk mail', 'chain letters,' or unsolicited mass mailing or 'spamming' or pyramid scams;\n- promotes information that you know is false or misleading or promotes illegal activities or conduct that is abusive, threatening, obscene, defamatory or libelous;\n- promotes an illegal or unauthorized copy of another person's copyrighted work, such as providing pirated computer programs or links to them, providing information to circumvent manufacture-installed copy-protect devices, or providing pirated music or links to pirated music files;\n- contains restricted or password-only access pages or hidden pages or images (those not linked to or from another accessible page);\n- provides material that exploits people under the age of 18 in a sexual or violent manner, or solicits personal information from anyone under 18;\n- provides instructional information about illegal activities such as making or buying illegal weapons, violating someone's privacy, providing or creating computer viruses;\n- solicits passwords or personal identifying information for commercial or unlawful purposes from other users; or\n- involves commercial activities and/or sales without our prior written consent such as contests, sweepstakes, barter, advertising, or pyramid schemes.\n- You must use the Service in a manner consistent with any and all applicable laws and regulations.\n- You may not include in your publicly accessible Member profile any telephone numbers, street addresses, last names, URLs, usernames from any social platforms or email addresses.\n- You may not engage in advertising to or solicitation of, any Member to buy or sell any products or services through the Service. You may not transmit any chain letters or junk email to other Members. Although we cannot monitor the conduct of its Members off the mobile application and website, it is also a violation of these rules to use any information obtained from the Service in order to harass, abuse, or harm another person, or in order to contact, advertise to, solicit, or sell to any Member without their prior explicit consent. In order to protect our Members from such advertising or solicitation, we reserve the right to restrict the number of messages which a Member may send to other Members in any period to a number which we deem appropriate in its sole discretion.\n- You may not attempt to impersonate another user or a person.\n- If you find illegal content during browsing, please report it to us immediately, we will take action on the offensive content report within 24 hours, delete the content and expel the user who provided the illegal content.\n- In order to create a good community operating environment, we will delete all illegal content. If you find illegal content but do not find an obvious report option, you can send us a screenshot of the relevant content by email.\n\n2. License.\n\nSubject to the terms of this EULA, XGames Live grants to you a limited and nonexclusive license (without the right to sublicense) to execute one (1) copy of the Product Software, in executable object code form only, solely on the Product that you own or control and solely for use in conjunction with the Product for your personal, non-commercial purposes.\n\n3. Restrictions.\n\nYou agree not to, and you will not permit others to, (a) license, sell, rent, lease, assign, distribute, transmit, host, outsource, disclose or otherwise commercially exploit the Product Software or make the Product Software available to any third party, (b) copy or use the Product Software for any purpose other than as permitted in Section 1, (c) use any portion of the Product Software on any device or computer other than the Product that you own or control, (d) remove or alter any trademark, logo, copyright or other proprietary notices, legends, symbols or labels in the Product Software, or (e) modify, make derivative works of, disassemble, reverse compile or reverse engineer any part of the Product Software (except to the extent applicable laws specifically prohibit such restriction for interoperability purposes, in which case you agree to first contact XGames Live and provide XGames Live an opportunity to create such changes as are needed for interoperability purposes). You may not release the results of any performance or functional evaluation of any of the Product Software to any third party without prior written approval of XGames Live for each such release.\n\n4. Automatic Software Updates.\n\nXGames Live may from time to time develop patches, bug fixes, updates, upgrades and other modifications to improve the performance of the Product Software and related services (“Updates”). These may be automatically installed without providing any additional notice or receiving any additional consent. You consent to this automatic update. If you do not want such Updates, your remedy is to stop using the Product. If you do not cease using the Product, you will receive Updates automatically. You acknowledge that you may be required to install Updates to use the Product and the Product Software and you agree to promptly install any Updates XGames Live provides. Your continued use of the Product is your agreement to this EULA.\n\n5. Ownership.\n\nThe Product Software and all worldwide copyrights, trade secrets, and other intellectual property rights therein are the exclusive property of XGames Live and its licensors. XGames Live and its licensors reserve all rights in and to the Product Software not expressly granted to you in this EULA. The Product Software (and all copies thereof) is licensed to you, not sold, under this EULA. There are no implied licenses in this EULA. All suggestions or feedback provided by you to XGames Live with respect to the Product Software shall be XGames Live’ property. XGames Live may use, copy, modify, publish, or redistribute the submission and its contents for any purpose and in any way without any compensation to you. You also agree that XGames Live does not waive any rights to use similar or related ideas previously known to XGames Live, developed by its employees, or obtained from other sources.\n\n6. Open Source.\n\nCertain items of software included with the Product Software are subject to “open source” or “free software” licenses (“Open Source Software”). Some of the Open Source Software is owned by third parties. The Open Source Software is not subject to the terms and conditions of this EULA. Instead, each item of Open Source Software is licensed under the terms of the end user license that accompanies such Open Source Software. Nothing in this EULA limits your rights under, or grants you rights that supersede, the terms and conditions of any applicable end user license for the Open Source Software. If required by any license for particular Open Source Software, XGames Live makes such Open Source Software, and XGames Live’ modifications to that Open Source Software, available by written request to XGames Live at the email or mailing address listed below.\n\n7. Term and Termination.\n\nThis EULA and the license granted hereunder are effective on the date you first use the Product Software or Product and shall continue for as long as you own the Product, unless this EULA is terminated under this section. XGames Live may terminate this EULA at any time if you fail to comply with any term(s) hereof. You may terminate this EULA effective immediately upon written notice to XGames Live. Upon termination of this EULA, the license granted hereunder will terminate and you must stop all use of the Product Software, but the terms of Sections 2 through 18 (inclusive) will remain in effect, after any such termination.\n\n8. Warranty Disclaimer.\n\nNOTWITHSTANDING ANYTHING TO THE CONTRARY AND TO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, XGames Live PROVIDES THE PRODUCT SOFTWARE “AS-IS” AND DISCLAIMS ALL WARRANTIES AND CONDITIONS, WHETHER EXPRESS, IMPLIED, OR STATUTORY, INCLUDING THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE, QUIET ENJOYMENT, ACCURACY, AND NON-INFRINGEMENT OF THIRD-PARTY RIGHTS. XGames Live DOES NOT GUARANTEE ANY SPECIFIC RESULTS FROM THE USE OF THE PRODUCT SOFTWARE. XGames Live MAKES NO WARRANTY THAT THE PRODUCT SOFTWARE WILL BE UNINTERRUPTED, FREE OF VIRUSES OR OTHER HARMFUL CODE, TIMELY, SECURE, OR ERROR-FREE.\n\nYOU USE ALL PRODUCT INFORMATION (AS DEFINED BELOW), THE PRODUCT SOFTWARE, AND THE PRODUCT AT YOUR OWN DISCRETION AND RISK. YOU WILL BE SOLELY RESPONSIBLE FOR (AND XGames Live DISCLAIMS) ANY AND ALL LOSS, LIABILITY, OR DAMAGES, INCLUDING TO YOUR HVAC SYSTEM, PLUMBING, HOME, PRODUCT, OTHER PERIPHERALS CONNECTED TO THE PRODUCT, COMPUTER, MOBILE DEVICE, AND ALL OTHER ITEMS AND PETS IN YOUR HOME, RESULTING FROM YOUR USE OF THE PRODUCT INFORMATION, PRODUCT SOFTWARE, OR PRODUCT.\n\n9. Limitation of Liability\n\nNothing in this EULA and in particular within this 'Limitation of Liability' clause shall attempt to exclude liability that cannot be excluded under applicable law.\n\nTO THE MAXIMUM EXTENT PERMITTED BY APPLICABLE LAW, IN ADDITION TO THE ABOVE WARRANTY DISCLAIMERS, IN NO EVENT WILL (A) XGames Live BE LIABLE FOR ANY CONSEQUENTIAL, EXEMPLARY, SPECIAL, OR INCIDENTAL DAMAGES, INCLUDING ANY DAMAGES FOR LOST DATA OR LOST PROFITS, ARISING FROM OR RELATING TO THE PRODUCTS OR PRODUCT SOFTWARE, EVEN IF XGames Live KNEW OR SHOULD HAVE KNOWN OF THE POSSIBILITY OF SUCH DAMAGES, AND (B) XGames Live’ TOTAL CUMULATIVE LIABILITY ARISING FROM OR RELATED TO THE PRODUCTS AND PRODUCT SOFTWARE, WHETHER IN CONTRACT OR TORT OR OTHERWISE, EXCEED THE FEES ACTUALLY PAID BY YOU TO XGames Live OR XGames Live’S AUTHORIZED RESELLER FOR THE PRODUCT AT ISSUE IN THE PRIOR 12 MONTHS (IF ANY). THIS LIMITATION IS CUMULATIVE AND WILL NOT BE INCREASED BY THE EXISTENCE OF MORE THAN ONE INCIDENT OR CLAIM. XGames Live DISCLAIMS ALL LIABILITY OF ANY KIND OF XGames Live’ LICENSORS AND SUPPLIERS.\n\n10. Limitations of Product Software\n\nYou acknowledge that the Products and Product Software are not certified for emergency response. YOU UNDERSTAND THAT THE PRODUCTS AND PRODUCT SOFTWARE ARE NOT A THIRD-PARTY MONITORED EMERGENCY NOTIFICATION SYSTEM -- XGames Live DOES NOT MONITOR EMERGENCY NOTIFICATIONS AND WILL NOT DISPATCH EMERGENCY AUTHORITIES TO YOUR HOME IN THE EVENT OF AN EMERGENCY. In addition, the XGames Live Customer Care and Support contacts cannot be considered a lifesaving solution for people at risk in the home, and they are no substitute for emergency services. All life threatening and emergency events should be directed to the appropriate response services.\nUnless explicitly promising a “guarantee,” XGames Live does not guarantee or promise any specific level of energy savings or other monetary benefit from the use of the Products or Product Software or any feature of them. Actual energy savings and monetary benefits vary with factors beyond XGames Live’ control or knowledge. From time to time, XGames Live may use the Product Software to provide you with information that is unique to you and your energy usage and suggests an opportunity to save money on energy bills if you adopt suggestions or features of the Product or Product Software. We do this to highlight an opportunity based on our analysis and information about you and your household. You acknowledge that these promotions are not a guarantee of actual savings, and you agree not to seek monetary or other remedies from XGames Live if your savings differ.\nThe Product Software provides you information (“Product Information”) regarding the Products in your home and their connection with other products and services. All Product Information is provided “as is” and “as available”. We cannot guarantee that it is correct or up to date. In cases where it is critical, accessing Product Information through the Product Software is not a substitute for direct access of the information in the home.\n\n11. Confidentiality.\n\n“Confidential Information” shall mean the Product Software and all other information disclosed to you that XGames Live characterizes as confidential at the time of its disclosure either in writing or orally, except for information which you can demonstrate: (a) is previously rightfully known to you without restriction on disclosure; (b) is or becomes, from no act or failure to act on your part, generally known in the relevant industry or public domain; (c) is disclosed to you by a third party as a matter of right and without restriction on disclosure; or (d) is independently developed by you without access to the Confidential Information. You shall use your best efforts to preserve and protect the confidentiality of the Confidential Information at all times, both during the term hereof and for a period of at least 3 years after termination of this EULA, provided, however, that any source code you receive shall be held in confidence in perpetuity. You shall not disclose, disseminate or otherwise publish or communicate Confidential Information to any person, firm, corporation or other third party without the prior written consent of XGames Live. You shall not use any Confidential Information other than in the course of the activities permitted hereunder. You shall notify XGames Live in writing immediately upon discovery of any unauthorized use or disclosure of Confidential Information or any other breach of this EULA, and will cooperate with XGames Live in every reasonable way to regain possession of Confidential Information and prevent any further unauthorized use. If you are legally compelled to disclose any of the Confidential Information, then, prior to such disclosure, you will (i) immediately notify XGames Live prior to such disclosure to allow XGames Live an opportunity to contest the disclosure, (ii) assert the privileged and confidential nature of the Confidential Information, and (iii) cooperate fully with XGames Live in protecting against any such disclosure and/or obtaining a protective order narrowing the scope of such disclosure and/or use of the Confidential Information. In the event such protection is not obtained, you shall disclose the Confidential Information only to the extent necessary to comply with the applicable legal requirements.\n\n12. For U.S. Government End Users.\n\nThe Product Software is a “commercial item,” as that term is defined at 48 C.F.R. 2.101 (OCT 1995), and more specifically is “commercial computer software” and “commercial computer software documentation,” as such terms are used in 48 C.F.R. 12.212 (SEPT 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (JUNE 1995), the Product Software is provided to U.S. Government End Users only as a commercial end item and with only those rights as are granted to all other customers pursuant to the terms and conditions herein.\n\n13. Export Compliance.\n\nThe Product Software and related technology are subject to U.S. export control laws and may be subject to export or import regulations in other countries. You agree to strictly comply with all such laws and regulations and acknowledge that you have the responsibility to obtain authorization to export, re-export, or import the Product Software and related technology, as may be required. You will indemnify and hold XGames Live harmless from any and all claims, losses, liabilities, damages, fines, penalties, costs and expenses (including attorney’s fees) arising from or relating to any breach by you of your obligations under this section.\n\n14. Governing Law; Venue.\n\nThe courts in some countries will not apply California law to some types of disputes. If you reside in one of those countries, then where California law is excluded from applying, your country’s laws will apply to such disputes related to these terms. Otherwise, you agree that this EULA, and any claim, dispute, action, cause of action, issue, or request for relief relating to this EULA, will be governed by the laws of California, without giving effect to any conflicts of laws principles that require the application of the laws of a different jurisdiction. Any action or proceeding relating to this EULA must be brought in a federal or state court located in Santa Clara County, California and each party irrevocably submits to the jurisdiction and venue of any such court in any such claim or dispute, except that XGames Live may seek injunctive relief in any court having jurisdiction to protect its intellectual property or Confidential Information.\n\n15. Assignment.\n\nNeither the rights nor the obligations arising under this EULA are assignable by you, and any such attempted assignment shall be void and without effect.\n\n16. Notices.\n\nAny notice to you may be provided by email to the address that you registered with XGames Live.\n\n17. Severability.\n\nIf any provision of this EULA is unenforceable, such provision will be changed and interpreted to accomplish the objectives of such provision to the greatest extent possible under applicable law and the remaining provisions will continue in full force and effect.\n\n18. Waiver.\n\nAll waivers by XGames Live will be effective only if in writing. Any waiver or failure by XGames Live to enforce any provision of this EULA on one occasion will not be deemed a waiver of any other provision or of such provision on any other occasion.\n\n19. General.\n\nThe Product Software is deemed irrevocably accepted upon your use of the Product Software or Product. XGames Live will have no responsibility to provide maintenance or support services with respect to the Product Software. The parties are independent contractors.\n\nYou acknowledge that the Product Software contains valuable trade secrets and proprietary information of XGames Live, that any actual or threatened breach of Section 2 (Restrictions) of this EULA will constitute immediate, irreparable harm to XGames Live for which monetary damages would be an inadequate remedy, and that injunctive relief is an appropriate remedy for such breach.\nThe headings of Sections of this EULA are for convenience and are not to be used in interpreting this EULA.\nExcept as otherwise provided in this section, no amendment to this EULA will be valid unless it is in writing hand-signed by the parties.\nQuestions or Additional Information. If you have questions regarding this EULA, please contact XGames Live at welkerkyle44@gmail.com."
            make.textColor = UIColor.hexColor("#A2A2A2")
            make.font = UIFont.pingfangSC_Regular(fontSize: 16.0)
            make.isEditable = false
            make.backgroundColor = .clear
        }
        let bottomButton = UIButton().then { make in
            make.setTitle("I Agree", for: .normal)
            make.setTitleColor(UIColor.hexColor("#191A1D"), for: .normal)
            make.titleLabel?.font = UIFont.pingfangSC_Regular(fontSize: 18.0)
            make.backgroundColor = UIColor.hexColor("#80FFE6")
            make.layerCornerRadius = 24.0
            make.addTarget(self, action: #selector(self.sureAction), for: .touchUpInside)
        }
        contentView.addSubviews([titleText,closeButton,textView,bottomButton])
        self.addSubview(contentView)
        titleText.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(26.0)
        }
        closeButton.snp.makeConstraints { make in
            make.centerY.equalTo(titleText)
            make.right.equalTo(-12.0)
            make.width.height.equalTo(24.0)
        }
        textView.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.left.equalTo(15.0)
            make.top.equalTo(titleText.snp.bottom).offset(10.0)
            make.height.equalTo(conversionWithScrennWidth(value: 385.0))
        }
        bottomButton.snp.makeConstraints { make in
            make.centerX.equalToSuperview()
            make.top.equalTo(textView.snp.bottom).offset(5.0)
            make.height.equalTo(48.0)
            make.left.equalTo(15.0)
        }
        contentView.snp.makeConstraints { make in
            make.center.equalToSuperview()
            make.width.equalTo(conversionWithScrennWidth(value: 345.0))
            make.bottom.equalTo(bottomButton.snp.bottom).offset(20.0)
        }
    }
}
